2C - Commentator problem - CodeForces Solution


geometry *2600

Please click on ads to support us..

Python Code:










import math

EPS = 1e-6
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

class Node:
    def __init__(self, x, y, r):
        self.x = x
        self.y = y
        self.r = r

def dis(a, b):
    return math.sqrt((a.x-b.x)**2 + (a.y-b.y)**2)

def check(p):
    ret = 0
    for i in range(1, 4):
        ret += ((dis(p, c[i])/c[i].r - dis(p, c[(i+1)%3+1])/c[(i+1)%3+1].r) ** 2)
    return ret

c = [None] * 4
p0 = Node(0, 0, 0)

for i in range(1, 4):
    x, y, r = map(float, input().split())
    c[i] = Node(x, y, r)
    p0.x += x/3
    p0.y += y/3

s = 1

while s > EPS:
    flag = True
    for i in range(4):
        p = Node(p0.x+dx[i]*s, p0.y+dy[i]*s, 0)
        if check(p) < check(p0):
            p0.x += dx[i] * s
            p0.y += dy[i] * s
            flag = False
    if flag:
        s /= 2

if check(p0) < EPS:
    print("{:.5f} {:.5f}".format(p0.x, p0.y))


Comments

Submit
0 Comments
More Questions

489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1